var UOLAF = window.UOLAF || {};

UOLAF.init = function () {
	if(!UOLAF.runOnce) {
		UOLAF.runOnce=true;
		/*
		UOLAF.atual=1;
		ss = document.getElementsByTagName('script');
		UOLAF.afs=0;
		console.debug(ss.length);
		for(i=0;i<ss.length;i++) { var now = ss[i];
			if(now.src.match(/uolaf.js$/)) {
				UOLAF.afs++;
			}
		}
		*/
		try {
			UOLAF.pg = Number((/UOLAFpg=([^|;]+)/).exec(document.cookie)[1]);
			//console.debug('leu '+UOLAF.pg)
		} catch(e) {
			UOLAF.pg = -1;
		}
        
	} else {
		//UOLAF.pg++;
	}
	UOLAF.ads();
}

UOLAF.ads = function () {
    adBlockCountLp = (typeof adBlockCountLp != "undefined")? adBlockCountLp + 1 : 0;
    UOLAF.pg++;
	UOLAF.pg = (UOLAF.pg>9)?0:UOLAF.pg;
	url  = 'http://adclient-af.lp.uol.com.br/';
	try{url += 'format'+formatId+'.html?&amp;';}catch(e){void(null)}
    try{url += 'adBlockCount='+adBlockCountLp+'&amp;';}catch(e){void(null)}
	try{url += 'page='+UOLAF.pg+'&amp;';}catch(e){void(null)}
	try{url += 'urlReferer='+encodeURIComponent(document.location.href)+'&amp;';}catch(e){void(null)}
	try{url += 'formatId='+formatId+'&amp;';}catch(e){void(null)}
	try{url += 'numads='+numads+'&amp;';}catch(e){void(null)}
	try{url += 'borderColor='+borderColor+'&amp;';}catch(e){void(null)}
	try{url += 'bgColor='+bgColor+'&amp;';}catch(e){void(null)}
	try{url += 'titleColor='+titleColor+'&amp;';}catch(e){void(null)}
	try{url += 'descrColor='+descrColor+'&amp;';}catch(e){void(null)}
	try{url += 'urlColor='+urlColor+'&amp;';}catch(e){void(null)}
	try{url += 'altColor='+altColor+'&amp;';}catch(e){void(null)}
	try{url += 'hasFrames='+hasFrames+'&amp;';}catch(e){void(null)}
	try{url += 'deslabel='+deslabel+'&amp;';}catch(e){void(null)}
	try{url += 'coddisplaysupplier='+coddisplaysupplier+'&amp;';}catch(e){void(null)}
    try{url += 'blank='+blank;}catch(e){void(null)}
	document.cookie = 'UOLAFpg='+UOLAF.pg;
	html = '<iframe src="'+url+'" ';
	html += 'marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" scrolling="no"';
	tipos = ['zeroIndex', [728,90], [468,60], [125,125], [234,60], [120,600], [160,600], [180,150], [120,240], [300,250], [250,250], [336,280] ];
	tipos[100] = [160, numads * 93.5];
	tipos[101] = [160, numads * 93.5];
	height = tipos[Number(formatId)][1];
	width  = tipos[Number(formatId)][0];
	html += 'height="'+height+'" width="'+width+'"></iframe>';
	document.write(html);
    if(typeof blank != "undefined" && blank == 1) blank = 0;
}


UOLAF.init();